package com.hanthink.web.controller.pc;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.system.domain.pc.EmFaultType;
import com.hanthink.system.service.pc.IEmFaultTypeService;
import com.hanthink.common.core.page.TableDataInfo;

/**
 * 故障类型Controller
 * 
 * @author hanthink
 * @date 2021-01-21
 */
@RestController
@RequestMapping("/equipment/faultType")
public class EmFaultTypeController extends BaseController
{
    @Autowired
    private IEmFaultTypeService emFaultTypeService;

    /**
     * 查询故障类型列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:faultType:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmFaultType emFaultType)
    {
        startPage();
        List<EmFaultType> list = emFaultTypeService.selectEmFaultTypeList(emFaultType);
        return getDataTable(list);
    }

    /**
     * 导出故障类型列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:faultType:export')")
    @Log(title = "故障类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EmFaultType emFaultType)
    {
        List<EmFaultType> list = emFaultTypeService.selectEmFaultTypeList(emFaultType);
        ExcelUtil<EmFaultType> util = new ExcelUtil<EmFaultType>(EmFaultType.class);
        return util.exportExcel(list, "faultType");
    }

    /**
     * 获取故障类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:faultType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(emFaultTypeService.selectEmFaultTypeById(id));
    }

    /**
     * 新增故障类型
     */
    @PreAuthorize("@ss.hasPermi('equipment:faultType:add')")
    @Log(title = "故障类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmFaultType emFaultType)
    {
        return toAjax(emFaultTypeService.insertEmFaultType(emFaultType));
    }

    /**
     * 修改故障类型
     */
    @PreAuthorize("@ss.hasPermi('equipment:faultType:edit')")
    @Log(title = "故障类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmFaultType emFaultType)
    {
        return toAjax(emFaultTypeService.updateEmFaultType(emFaultType));
    }

    /**
     * 删除故障类型
     */
    @PreAuthorize("@ss.hasPermi('equipment:faultType:remove')")
    @Log(title = "故障类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emFaultTypeService.deleteEmFaultTypeByIds(ids));
    }
}
